package com.example.financechain.controller;


import com.alibaba.fastjson.JSON;
import com.example.financechain.Utils.JsonData;
import com.example.financechain.domain.DTO.AuditBusiness;
import com.example.financechain.domain.entity.Business;
import com.example.financechain.service.IBusinessService;
import org.hyperledger.fabric.gateway.ContractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.cert.CertificateException;
import java.util.concurrent.TimeoutException;

/**
 * <p>
 * 订单信息表 前端控制器
 * </p>
 *
 * @author yy
 * @since 2023-04-22
 */
@RestController
@RequestMapping("private/business")
public class BusinessController {

    @Autowired
    IBusinessService iBusinessService;

    /**
     * 创建业务
     * @param business
     * @return
     */
    @PostMapping("/create/business")
    public JsonData CreateBusiness(@RequestBody Business business){
        return iBusinessService.createBusiness(business);
    }


    /**
     * 接受业务办理公司代办列表
     * @return
     */
    @GetMapping("/query/business")
    public JsonData QueryBussinesslist(){
        return iBusinessService.querybusiness();
    }


    /**
     *  发起业务的公司消息通知
     * @return
     */
    @GetMapping("/query/start")
    public JsonData startmessagelist(){
        return  iBusinessService.queryStart();
    }


    /**
     * 进去审核的界面
     * @param id
     * @return
     */
    @GetMapping("/query/business/{id}")
    public JsonData audit(@PathVariable("id") Long id ){

        return iBusinessService.querybusinessbyId(id);

    }


    /**
     * 审核
     */
    @PostMapping("/audit/business")
    public JsonData auditBusiness(@RequestBody AuditBusiness auditBusiness) throws ContractException, CertificateException, IOException, InvalidKeyException, InterruptedException, TimeoutException {

        return iBusinessService.auditBusiness(auditBusiness);
    }




}
